/*
 * @Author: harity
 * @Date: 2021-07-28 17:18:17
 * @LastEditTime: 2021-07-28 17:30:02
 * @LastEditors: Please set LastEditors
 * @Description: 节流
 * @FilePath: /learn-js/src/throttle.js
 */

/**
 * @description: 节流，在n秒内只会执行一次
 * @param {*} cb
 * @param {*} wait
 * @return {*}
 */
function throttle(cb,wait = 500){
    let lastTime = 0
    return function(...arg){
        const now = Date.now()
        if(now - lastTime > wait){
            lastTime = now
            cb.apply(this,arg)
        }
    }
}

const fun = throttle(()=>{console.log(111)},10000)
setInterval(fun,1)